import type { Component } from 'vue';
import type { ComponentType } from './types';

/**
 * Component list, register here to setting it in the form
 */

import * as AntdComponents from 'ant-design-vue/es/components';

import ApiRadioGroup from './components/ApiRadioGroup.vue';
import RadioButtonGroup from './components/RadioButtonGroup.vue';
import ApiSelect from './components/ApiSelect.vue';
import ApiTree from './components/ApiTree.vue';
import ApiTreeSelect from './components/ApiTreeSelect.vue';
import ApiCascader from './components/ApiCascader.vue';
import ApiTransfer from './components/ApiTransfer.vue';
import { BasicUpload, Uploader, ImageUpload } from '/@/components/Upload';

// import { StrengthMeter } from '/@/components/StrengthMeter';
// import IconPicker from '/@/components/Icon/src/IconPicker.vue';

import { CountdownInput } from '/@/components/CountDown';
import { BasicTitle } from '@/components/Basic';

const componentMap = new Map<ComponentType | string, Component>();
componentMap.set('ImageUpload', ImageUpload);
componentMap.set('ApiSelect', ApiSelect);
componentMap.set('ApiTree', ApiTree);
componentMap.set('ApiTreeSelect', ApiTreeSelect);
componentMap.set('ApiRadioGroup', ApiRadioGroup);

componentMap.set('Upload', BasicUpload);

componentMap.set('RadioButtonGroup', RadioButtonGroup);

componentMap.set('ApiCascader', ApiCascader);

componentMap.set('ApiTransfer', ApiTransfer);

// componentMap.set('StrengthMeter', StrengthMeter);

componentMap.set('InputCountDown', CountdownInput);

componentMap.set('Uploader', Uploader);

// componentMap.set('IconPicker', IconPicker);

componentMap.set('BasicTitle', BasicTitle);

for (const key in AntdComponents) {
  const comp = AntdComponents[key];
  //组件没有name,跳过。比如Messasge.success
  if (!comp.name) {
    continue;
  }
  if (!componentMap.has(comp.name)) {
    add(comp.name, comp);
  }
}

export function add<T extends string, R extends Component>(
  compName: ComponentType | T,
  component: R,
) {
  componentMap.set(compName, component);
}

export function del<T extends string>(compName: ComponentType | T) {
  componentMap.delete(compName);
}

export { componentMap };
